/**
 * @file CommandLineEdit.h Contains the declaration CommandLineEdit which is in
 * charge to present the user the ability to type some commands into a singele
 * line.
 *
 * @author <a href="ojlr@informatik.uni-bremen.de">Ole Jan Lars Riemann</a>
 */

#pragma once

#include <QLineEdit>

class Console;
class CommandLineCompleter;

/** A QLineEdit which acts more like the last line of a unix shell than a pure
 * QLineEdit.
 */
class CommandLineEdit : public QLineEdit
{
  /** The console which uses the instance of the CommandLineEdit. */
  Console *console;

  /** The history of the command line. */
  QStringList history;

  /** The current position in the history.
   * (Can be changed with cursor up and cusor down)
   */
  QStringList::Iterator historyIter;

  /** The completer which is in charge to show a popup with completions
   * suggestions.
   */
  CommandLineCompleter *completer;

protected:
  /** Disables Focus switch on tab key and triggers completion instead.
   * All other events are relayed to the method of the superclass
   * @link QLineEdit
   * @copydoc QLineEdit::eventFilter(QObject*,QEvent*)
   */
  bool eventFilter(QObject *o, QEvent *e);

  /** Triggers the completer.
   * This means a completer popup is shown which suggests some possible
   * completions as generated by @link Commands::complete(const std::string&).
   */
  void complete();

public:
  explicit CommandLineEdit(Console *parent);

  /**
   * Overwrites the keyPressEvent mehtod of the the QLineEdit to handle special
   * keys in a special way.
   */
  void keyPressEvent(QKeyEvent *e);
};
